using System;
using System.Collections.Generic;
using UnityEngine;

public static class Widget
{
	public static T Create<T>() where T : MonoBehaviour
	{
		string text = typeof(T).Name.Replace("Handler", string.Empty);
		if (!Widget.resourceCache.ContainsKey(text))
		{
			GameObject gameObject = Resources.Load("widgets/" + text) as GameObject;
			if (gameObject == null)
			{
				UnityEngine.Debug.LogError("No " + text + ".prefab found in Resources folder!");
				return (T)((object)null);
			}
			Widget.resourceCache[text] = gameObject;
		}
		GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(Widget.resourceCache[text], Vector3.zero, Quaternion.identity);
		if (gameObject2 == null)
		{
			UnityEngine.Debug.LogError("Widget.Create Fail : " + typeof(T).FullName);
			return (T)((object)null);
		}
		return gameObject2.GetComponent<T>();
	}

	private static Dictionary<string, GameObject> resourceCache = new Dictionary<string, GameObject>();
}
